package br.com.players.resource;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import br.com.players.model.Convite;
import br.com.players.service.CadastroConviteService;

@Path("/cadastro/convite")
public class CadastroConvites {
	
	private CadastroPlayer cadastroPlayer =  new CadastroPlayer();
	private CadastroTime cadastroTime = new CadastroTime();
	private CadastroConviteService cadastroConviteService = new CadastroConviteService();
	
	@POST
	@Path("/conviteParticiparTime")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public String cadastrarConviteParticipaTime(@FormParam("email") String email, @FormParam("idTime") String idTime) {
		
		String retorno = null;
		
		if(email != null && idTime != null) {
			retorno = new CadastroConviteService().inserirConvite(email, idTime);
		} else {
			retorno = "-1";
		}
		
		return retorno;
	}
	
	
	@GET
	@Path("/buscar/convites/player")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Convite> buscarConvites(@QueryParam("id") String id) {
		return cadastroConviteService.buscarConvitesPorPlayer(id);
	}
	
	@POST
	@Path("/remover/convite")
	@Produces(MediaType.APPLICATION_JSON)
	public String removerConvitesPorID(@FormParam("idConvite") String idConvite) {
		return cadastroConviteService.removerConvitePorID(idConvite);
	}
	
	@POST
	@Path("/inserir/player/time")
	@Produces(MediaType.APPLICATION_JSON)
	public String inserirPlayerTime(@FormParam("idTime") String idTime, @FormParam("idPlayer") String idPlayer, @FormParam("idConvite") String idConvite) {
		return cadastroConviteService.inserirPlayerTime(idTime, idPlayer, idConvite);
	}
}